<template>
  <div class="login-container">
    <div class="login-wrap">
      <div class="title">会员登录</div>
      <input type="text" placeholder="请输入用户名" v-model="userName" />
      <input type="password" placeholder="请输入密码" v-model="passWord" @keyup.enter="handleLogin" />
      <button @click="handleLogin">登录</button>
    </div>
  </div>
</template>
<script>
// import moment from 'moment';
import { login, setDefaultToken } from '../../api'; 

export default {
  name: "Login",
  components: {},
  data() {
    return {
      userName: "",
      passWord: "",
    };
  },
  methods: {
    // 用户登录    
    handleLogin() {
      login({
        username: this.userName,
        password: this.passWord,
      }).then(res => {
        setDefaultToken(`${res.tokenHead} ${res.token}`);
        sessionStorage.setItem('loginInfo', JSON.stringify({ ...res, user: this.userName }));
        this.$router.push('/main');
      });
    },
  },
  mounted() {},
  beforeDestroy() {},
};
</script>

<style lang="scss" scoped>
.login-container {
  position: relative;
  height: 100vh;
  overflow: hidden;
  background: url(../../assets/login-bg.jpg) center no-repeat;
  background-size: cover;
  .login-wrap {
    position: absolute;
    right: 12%;
    bottom: 0;
    top: 0;
    margin: auto 0;
    width: 400px;
    height: 300px;
    background-color: transparent;
    box-shadow: 0 0 6px 1px #f5f5f5;
    padding: 16px;
    .title {
      font-size: 20px;
      color: #fff;
      border-bottom: 2px solid #fff;
      line-height: 48px;
      margin-bottom: 30px;
      span {
        position: relative;
        float: right;
        font-size: 14px;
        color: #69c0ff;
        cursor: pointer;
      }
    }
    input {
      width: 400px;
      line-height: 40px;
      outline: none;
      font-size: 16px;
      margin-bottom: 32px;
      padding-left: 12px;
      box-sizing: border-box;
      background-color: rgba(33, 33, 33, 0.1);
      border: none;
      color: #fff;
      &::-webkit-input-placeholder {
        color: #bbb;
      }
    }

    button {
      width: 400px;
      height: 40px;
      line-height: 40px;
      font-size: 20px;
      color: #fff;
      background-color: #fa541c;
      outline: none;
      border: none;
      cursor: pointer;
      letter-spacing: 1em;
    }
  }
}
</style>
